package com.example.userprovider.dto;

import org.example.exception.ValidException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import javax.validation.constraints.NotNull;

/**
 * @author
 * @date 2021-4-16 15:03
 */
public class AuthLoginDto {
    /**
     * 登陆账号
     */
    private String username;
    /**
     * 登录密码
     */
    private String password;
    /**
     * 手机号
     */
    private String phone;
    /**
     * 微信id
     */
    private String openId;
    /**
     * 登录类型
     * @see LoginTypeEnum
     */
    @NotNull(message = "登录类型不能为空")
    private Integer loginType;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public Integer getLoginType() {
        return loginType;
    }

    public void setLoginType(Integer loginType) {
        this.loginType = loginType;
    }
    public void validData(BindingResult bindResult) {
        if(bindResult.hasErrors()) {
            StringBuilder sb = new StringBuilder();
            for (ObjectError error : bindResult.getAllErrors()) {
                sb.append(error.getDefaultMessage()+"\n");
            }
            throw new ValidException(sb.toString());
         }
    }
}
